<template>
	<view class="personalInformation">
		<view class="card">
			<view class="header">
				<view class="circle"></view>
				<text>员工信息</text>
				<view class="headerText">需要填写以下信息，以进行资质审查，所有填写的信息仅 用于认证，平台绝不外泄。</view>
			</view>
		</view>
		<block v-for="(i, j) in list" :key="j">
			<view class="card" @click="toGo(i.url,i.pageName)">
				<view class="infoStyle flex-between">
					<view>
						<text>{{ i.name }}</text>
						<view class="infoText">{{ i.text }}</view>
					</view>
					<view v-if="!i.editBoolen" :class="[i.disable?'btnGayUpdata flex':'btnUpdata flex'] "><span
							style="font-size: 14px;">去上传</span></view>
					<view v-if="i.editBoolen" class="btnUpdata flex"><span
									style="font-size: 14px;">去编辑</span></view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState,
			mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				list: [{
						name: '身份认证',
						text: '请上传员工的正反面身份证照片',
						url: '/pages/personalInformation/identityAuthentication/index',
						pageName:"identityAuthentication",
						disable: false,
						editBoolen:false
					},
					{
						name: '相册',
						text: '请上传员工相册',
						url: '/pages/personalInformation/uploadAvatar/index',
						pageName:"uploadAvatar",
						disable: false,
						editBoolen:false
					},
					{
						name: '资质信息',
						text: '请上传从业资格证书照片',
						url: '/pages/personalInformation/uploadQualification/index',
						pageName:"uploadQualification",
						disable: false,
						editBoolen:false
					},
					{
						name: '健康信息',
						text: '请上传有效期内的健康证照片',
						url: '/pages/personalInformation/uploadHealthCertificate/index',
						pageName:"uploadHealthCertificate",
						disable: false,
						editBoolen:false
					},
					
					{
						name: '基本资料',
						text: '身高/员工简介等基本信息',
						url: '/pages/personalInformation/basicInformation/index',
						pageName:"basicInformation",
						disable: false,
						editBoolen:false
					},
					// {
					// 	name: '服务类目',
					// 	text: '请选择你要从事的服务',
					// 	url: '/pages/serviceItems/serviceItems',
					// 	pageName:"serviceItems",
					// 	disable: false
					// },
				]
			};
		},

		onShow() {
			this.init()
		},
		computed: {
			
			...mapGetters('user', ['addstr','technicianDetails']),
		},
		methods: {
			
			
			init() {
			     console.log('启动======================')
				if(this.technicianDetails.authenticationNot==3){
			
					for (let i = 0; i < this.list.length; i++) {
						this.list[i].editBoolen = true
					}
				}else{
					const index = this.list.findIndex(item => {
						return item.pageName == this.addstr?.name
					})
					this.currentIndx = index
					console.log(index)
					// 当前的状态 然后把前面的状态变为true
					if (index !== -1) {
						// -1 状态 有二种情况 
						for (let i = 0; i < this.currentIndx; i++) {
							this.list[i].disable = true
						}
					}else{
						if(this.addstr?.name=='serviceItemsEnd'){
							for (let i = 0; i <= this.list.length-1; i++) {
								this.list[i].disable = true
							}
						}
					}
				}
			
			},
			toGo(url, pageName) {
				if(this.technicianDetails.authenticationNot==3){
					this.$sun.navGo(url)
				}else{
					console.log(this.addstr?.name)
					// z这里需要判断如果所有的都 禁用那么不能在点击上传
					const res=this.list.filter((item)=>{
						return item.disable!==true
					})
					console.log(res)
					
					if(res.length){
						if ((this.addstr.name ? this.addstr?.name : 'identityAuthentication') == pageName) {
							this.$sun.navGo(url)
						} else {
							const selectPage = this.addstr.name ? this.addstr.name : 'identityAuthentication'
							if(selectPage=='serviceItemsEnd'){
								this.$sun.navGo(url)
							}else{
								if (selectPage == 'identityAuthentication') {
									this.$sun.toast('请上传员工的正反面身份证照片')
								} else if (selectPage == 'uploadAvatar') {
									this.$sun.toast('请上传员工头像和相册')
								} else if (selectPage == 'uploadQualification') {
									this.$sun.toast(' 请上传从业资格证书照片')
								} else if (selectPage == 'uploadHealthCertificate') {
									this.$sun.toast('请上传有效期内的健康证照片')
								} else if (selectPage == 'serviceItems') {
									this.$sun.toast('请先设置服务项目')
								}
								
							}
						}
					}else{
						// 当所有填完以后就是真正审核中
							this.$sun.toast('正在审核请耐心等待')
					}
				}
			
			    

			}

		}
	};
</script>

<style lang="less" scoped>
	page {
		background-color: #666;
	}

	.personalInformation {
		.card {
			margin-top: 4rpx;
			padding: 22rpx;
			background-color: #fff;

			.header {
				.circle {
					width: 28rpx;
					height: 28rpx;
					background-color: #1890ff;
					display: inline-block;
					border-radius: 50%;
					margin-right: 12rpx;
				}

				.headerText {
					margin-top: 15rpx;
					color: #666;
					font-size: 28rpx;
				}
			}

			.infoStyle {
				padding: 20rpx;
				box-sizing: content-box;

				.infoText {
					margin-top: 15rpx;
					color: #666;
					font-size: 28rpx;
				}

				.btnUpdata {
					width: 140rpx;
					height: 64rpx;
					border-radius: 76rpx;
					border: 2rpx solid #1890ff;
					color: #1890FF;
					background: #fff;
				}

				.btnGayUpdata {
					width: 140rpx;
					height: 64rpx;
					border-radius: 76rpx;
					border: 2rpx solid #666;
					color: #666;
					background: #fff;
				}
				// .editUpdata{
				// 	width: 140rpx;
				// 	height: 64rpx;
				// 	border-radius: 76rpx;
				// 	border: 2rpx solid #666;
				// 	color: #666;
				// 	background: #fff;
				// }
			}
		}
	}
</style>